#pragma once

#include "clkHeader.h"
#include "clkObject.h"

class clkCell
{
public:
	V2DF m_pos;
	float m_row, m_col;
	List<clkObject*> m_objects;

	void init(V2DF a_pos, float a_col, float a_row)
	{m_pos = a_pos; m_col = a_col; m_row = a_row;}

	void destroy()
	{m_objects.release();}

	void add(clkObject* a_object)
	{m_objects.insertBack(a_object);}

	void remove(clkObject* a_object)
	{m_objects.removeData(a_object);}

	int size(){return m_objects.size();}

	clkObject* get(int a_index)
	{return m_objects[a_index];}
};

class clkPartitioner
{
public:
	float m_cellWidth;
	float m_cellHeight;
	List<clkCell*> m_cells;
	MemPool<clkCell> m_pool;

	void init(float a_cellWidth, float a_cellHeight);
	void destroy();
	void partition(clkObject* a_object);

	void clearCells();

	bool cellExist(clkCell** a_out, clkCell* a_test);
	bool createCell(clkCell** a_out, clkCell* a_test);

	void getCellPos(List<V2DF*>* m_pos);
};